package cn.edu.cdu.group4nb.service.impl;

import cn.edu.cdu.group4nb.mapper.PageMapper;
import cn.edu.cdu.group4nb.mapper.RoleMapper;
import cn.edu.cdu.group4nb.mapper.UserInfMapper;
import cn.edu.cdu.group4nb.mapper.UserMapper;
import cn.edu.cdu.group4nb.po.PageInf;
import cn.edu.cdu.group4nb.po.RoleInf;
import cn.edu.cdu.group4nb.po.UserInf;
import cn.edu.cdu.group4nb.service.UserInfoService;
import cn.edu.cdu.group4nb.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @auther: tupeng
 * @date: 2019-10-09 12:36
 */
@Service
public class UserServiceImpl implements UserService {
    private final UserMapper userMapper;
    private final RoleMapper roleMapper;
    private final PageMapper pageMapper;
    @Autowired
    public UserServiceImpl(UserMapper userMapper, RoleMapper roleMapper, PageMapper pageMapper) {
        this.userMapper = userMapper;
        this.roleMapper = roleMapper;
        this.pageMapper = pageMapper;
    }


//    @Autowired
//    public UserServiceImpl(UserMapper userMapper) {
//        this.userMapper = userMapper;
//    }


    @Override
    public boolean checkUserName(String userid) {
        UserInf userInf = userMapper.queryUserInfByName(userid);
        System.out.println(userInf);
        return userInf == null ? false : true;

    }

    @Override
    public void Register(UserInf userInf) {
        userMapper.registertUserInfo(userInf);
    }

    @Override
    public void updatePassword(String newPassword, String username) {
        userMapper.updatePassword(newPassword, username);
    }

    @Override
    public List<UserInf> queryAllUser() {
        return userMapper.queryAllUser();
    }

    @Override
    public void addUser(UserInf userInf) {
        userMapper.addUser(userInf);
    }

    @Override
    public void deleteUser(int[] user_info_id) {
        userMapper.deleteUser(user_info_id);
    }

    @Override
    public RoleInf queryUserById(int user_info_id) {
        return userMapper.queryUserById(user_info_id);
    }

    @Override
    public void updateUser(String userid, String password, String name, String githubURL, String email, String user_info_id) {
        userMapper.updateUser(userid,password,name,githubURL,email,user_info_id);
    }

    @Override
    public List<RoleInf> getRoleById(int user_info_id) {
        return roleMapper.getRoleById(user_info_id);
    }

    @Override
    public void addRoleToUser(RoleInf roleInf) {
          roleMapper.addRoleToUser(roleInf);
    }

    @Override
    public void deleteRoleFromUser(int[] roleid) {
        roleMapper.deleteRoleFromUser(roleid);
    }



    @Override
    public List<PageInf> getPageById(int roleid) {
        return pageMapper.getPageById(roleid);
    }

    @Override
    public void addPageToRole(PageInf pageInf) {
        pageMapper.addPageToRole(pageInf);
    }

    @Override
    public PageInf queryPageByRoleId(int roleid) {
        return pageMapper.queryPageByRoleId(roleid);
    }

    @Override
    public void deletePageFromRole(int[] pageid) {
            pageMapper.deletePageFromRole(pageid);
    }

    @Override
    public List<PageInf> queryAllPage() {
        return pageMapper.queryAllPage();
    }

}
